package com.zxl.grocery;

import com.zxl.grocery.config.properties.GroceryProperties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * SpringBoot 方式启动类
 * Created by Lzx on 2017/7/3.
 *
 */
@SpringBootApplication
public class GroceryApplication extends WebMvcConfigurerAdapter {

	protected final static Logger logger = LoggerFactory.getLogger(GroceryApplication.class);

	@Autowired
	GroceryProperties groceryProperties;

	/**
	 * 增加swagger的支持
	 */
	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		if(groceryProperties.getSwaggerOpen()){
			registry.addResourceHandler("swagger-ui.html").addResourceLocations("classpath:/META-INF/resources/");
			registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
		}
	}

	public static void main(String[] args) {
		SpringApplication.run(GroceryApplication.class, args);
		logger.info("GroceryApplication is success!");
	}
}